const util = require('../../utils/util.js');
const api = require('../../config/api.js');
//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    scrollHeight: '',
    pagination: {
      page: 1,
      size: 5,
      user_id: 0
    },
    totalPage: 0,
    scrollTop: 0,
    hidden: false,
    pageTip: '加载中...',
    noData: false,
    items: []
  },
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
    that.data.pagination.user_id = options.id;
    that.getList();
  },
  /**
   * 绑定滚动事件
  */
  bindDownLoad: function (event) {
    let self = this;
    if (self.data.pagination.page == self.data.totalPage) {
      self.setData({
        noData: true
      });
      return false;
    }
    if (self.data.pagination.page != self.data.totalPage) {
      self.data.pagination.page += 1;
    }
    this.getList();
  },
  /**
   * 获取房间列表api
  */
  getList: function () {
    let self = this;
    self.setData({
      hidden: false
    });
    util.request(api.roomQRCodeUrl, self.data.pagination, 'post').then(function (res) {
      if (res.errno === 0) {
        self.data.items.push.apply(self.data.items, res.data.data);
        self.setData({
          items: self.data.items,
        });
        self.data.totalPage = res.data.totalPages
      }
      self.setData({
        hidden: true
      });
    });
  }
})
